package com.dz.risk.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.dz.risk.common.ResponseVO;
import com.dz.risk.common.exception.RRException;
import com.dz.risk.common.utils.ResponseUtils;
import com.dz.risk.pojo.QueryParams;
import com.dz.risk.pojo.domain.ProprietaryValuationOfBondHoldingsInformationEntity;
import com.dz.risk.service.ProprietaryValuationOfBondHoldingsInformationService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;


/**
 * 自营估值债券持仓信息-上游数据
 *
 * @author yinpl
 * @email 
 * @date 2021-07-08 09:24:19
 */
@RestController
@RequestMapping("dz-ftsp/stest/proprietaryvaluationofbondholdingsinformation")
@Api(tags = "自营估值债券持仓信息api", value = "自营估值债券持仓信息接口")
public class ProprietaryValuationOfBondHoldingsInformationController {
    @Autowired
    private ProprietaryValuationOfBondHoldingsInformationService proprietaryValuationOfBondHoldingsInformationService;
    private final Logger logger = LoggerFactory.getLogger(this.getClass());

    /**
     * 查询自营估值债券持仓信息
     *
     */
    @ApiOperation("查询自营估值债券持仓信息")
    @PostMapping(value = "/query")
    public ResponseVO query(@RequestBody QueryParams queryParams) {
        IPage<ProprietaryValuationOfBondHoldingsInformationEntity> iPage =null;
        try {
            iPage = proprietaryValuationOfBondHoldingsInformationService.query(queryParams);
        } catch (RRException e) {
            e.printStackTrace();
            logger.error("查询日志信息失败！" + e);
            return new ResponseVO(e.getCode(), e.getMessage());
        }
        return ResponseVO.ok(iPage);

    }

    @ApiOperation("导出自营估值债券持仓信息")
    @GetMapping("/doExport")
    public void doExport(HttpServletResponse response,QueryParams queryParams) throws IOException {
        final String fileName = "自营估值债券持仓信息_%s.xlsx";
        proprietaryValuationOfBondHoldingsInformationService.doExportByVersion(response, queryParams);
    }

}
